import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import sun.util.resources.ms.CalendarData_ms_MY;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Text1 {
    public static void main(String[] args) throws SQLException {
        Scanner sc = new Scanner(System.in);
        int id=0,grade=0,county_ranking;
        String name = null,subject = null;
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/va_system?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("Aa20021203X");

        Connection connection = dataSource.getConnection();

        int i=5;
        while(i!=0){
            System.out.println("id:");
            id=sc.nextInt();
            System.out.println("name:");
            name=sc.nextLine();
            System.out.println("subject:");
            subject=sc.nextLine();
            System.out.println("grade:");
            grade = sc.nextInt();
            System.out.println("count_ranking");
            county_ranking= sc.nextInt();
            String sql =("insert into student value(?,?,?,?,?)");
            PreparedStatement statement =connection.prepareStatement(sql);
            statement.setInt(1,id);
            statement.setString(2,name);
            statement.setString(3,subject);
            statement.setInt(4,grade);
            statement.setInt(5,county_ranking);
            int ret = statement.executeUpdate();
            System.out.println(ret);
            statement.close();
            connection.close();
        }


    }
}
